{extend name="public/base" /}

{block name="title"}<title>公告审核</title>{/block}

{block name="pjax_container"}
<style>
    tr>th,
    td {
        text-align: center;
    }



    .content-header>.breadcrumb>li {
        color: #999;
    }

    .content-header>.breadcrumb>.active {
        color: #666;
    }

    .content-header {
        height: 51px;

    }

    .btn-primary {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 5px 10px;
        height: 34px;
    }

    .box-primary {
        border-top-color: #ecf0f5 !important;
        border-top-width: 16px;

    }

    .btn-primary:hover {
        background-color: #1890FF;
        color: #fff;
        border: none;
        opacity: .9;
        border-radius: 6px !important;
    }

    .delete-one {
        background-color: ff4141 !important;
        margin-left: 15px;
        border-radius: 6px;
    }

    .sreachs {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 7px 15px;
    }

    .nav-tabs-custom {
        margin-bottom: 20px;
        background: #fff;
        box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
        border-radius: 3px;
        margin-top: 16px;
    }

    tr>th,
    td {
        text-align: center;
    }


.plsh{
    height: 34px;
    margin-top: 3px;
}
.plbh{
    background-color: #f39c12
}
.plch{background-color: red}
</style>
<section class="content-header">
    <ol class="breadcrumb">
        <li>任务大厅</li>
        <li class="active">公告审核</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                {include file="form_search/search_notice" /}
                <div class="box-header with-border" style="padding: 0;padding-left: 10px;">
                    <div class="pull-left">
                        <a href="{:url('audit')}" class="btn btn-sm task_nav_an"><i class="fa fa-save"></i> 任务审核</a>
                        <a href="{:url('audit_notice')}" class="btn btn-sm task_nav_an task_nav_an_active"><i class="fa fa-save"></i> 公告审核</a>
                    </div>
                    <a class="btn btn-primary plsh" href="javascript:void(0);" data-title="批量审核" data-url="/company/task/notice_pass_list"><i class='fa fa-save'></i>批量审核</a>
                    <a class="btn btn-primary plbh" href="javascript:void(0);" data-url="/company/task/notice_reject_list" data-title="确认驳回?"><i class='fa fa-repeat'></i>批量驳回</a>
                    <a class="btn btn-primary plch" href="javascript:void(0);" data-url="/company/task/notice_withdraw_list" data-title="确认撤回?"><i class='fa fa-reply'></i>批量撤回</a>
                </div>
                <div class="box-body table-responsive">
                    <table class="table table-bordered table-hover">
                        <tr>
                            <th width="35"><input type="checkbox" class="minimal checkbox-toggle"></th>
                            <th>任务名称</th>
                            <th>初审人</th>
                            <th>终审人</th>
                            <th>截止时间</th>
                            <th>阅读奖分</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        {volist name="$list" id="v"}
                        <tr>
                            <td><input type="checkbox" name="id[]" value="{$v.id}" data-status="{$v.status}" data-fuser="{$v.first_check_user_id}" data-luser="{$v.last_check_user_id}" data-ruser="{$v.record_user_id}" class="minimal checkbox"></td>
                            <td><a href="{:url('task/notice_info',['id'=>$v.id])}">{$v["name"]}</a></td>
                            <td>{$v["b_name"]}</td>
                            <td>{$v["c_name"]}</td>
                            <td>{:date('Y-m-d H:i:s',$v["end_time"])}</td>
                            <td>{$v["read_integral"]}分</td>
                            <td>
                                {if condition="$v.status eq 0"}
                                待初审
                                {elseif condition="$v.status eq 1"}
                                待终审
                                {elseif condition="$v.status eq 2"}
                                公示中
                                {elseif condition="$v.status eq 3"}
                                已截止
                                {elseif condition="$v.status eq 4"}
                                拟稿
                                {/if}
                            </td>
                            <td>
                                <form class="form-horizontal" style="display: inline-block" method="POST"
                                    action="{:url('notice_pass')}" onsubmit="return false">
                                    <input type="hidden" name="id" value='{$v["id"]}' />
                                    <input type="hidden" name="check_opinion" value='' />
                                    {if condition="in_array($v.status,[0,1])"}
                                    <!--通过-->
                                    <!--驳回-->
                                    {if condition="$v.status == 0 && $v.first_check_user_id == $user_id"}
                                    <button type="submit" class="btn btn-primary audit_sub_submit"><i
                                            class='fa fa-save'></i> 通过</button>
                                    <button type="submit" class="btn btn-warning bh_sub_submit bh"><i
                                            class='fa fa-repeat'></i> 驳回</button>
                                    {elseif condition="$v.status == 1 && $v.last_check_user_id == $user_id"}
                                    <button type="submit" class="btn btn-primary audit_sub_submit">
                                        <i class="fa fa-save"></i> 通过</button>
                                    <button type="submit" class="btn btn-warning bh_sub_submit bh">
                                        <i class="fa fa-repeat"></i> 驳回</button>
                                    {/if}
                                    <!--撤回-->
                                    {if condition="$v.status == 0 && $v.record_user_id == $user_id"}
                                    <!--<button type="submit" id="ch" class="btn btn-danger"><i-->
                                            <!--class='fa fa-reply'></i> 撤回</button>-->
                                    {elseif condition="$v.status == 1 && $v.first_check_user_id == $user_id"}
                                    <button type="submit" id="ch" class="btn btn-danger ch_sub_submit ch"><i
                                            class='fa fa-reply'></i> 撤回</button>
                                    {/if}
                                    {/if}
                                    <button class="submits hidden"></button>
                                </form>
                            </td>
                        </tr>
                        {/volist}
                    </table>
                </div>
                <div class="box-footer clearfix">
                    {$list->render()}
                </div>
            </div>
        </div>
    </div>
</section>
<script>
    $(function () {
        // 列表部分 全选
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal-blue'
        });
        $('.checkbox-toggle').on('ifChecked', function (event) {
            var _this = $(this);
            var _table = _this.closest('.table');
            _table.find("tr td input[type='checkbox']").iCheck("check");
        });
        $('.checkbox-toggle').on('ifUnchecked', function (event) {
            var _this = $(this);
            var _table = _this.closest('.table');
            _table.find("tr td input[type='checkbox']").iCheck("uncheck");
        });
    });
    //点击撤回，修改from提交地址
    $('.bh').on('click', function () {
        $(this).parents(".form-horizontal").attr('action', "{:url('notice_reject')}");
    })
    $('.ch').on('click', function () {
        console.log(111222);
        $(this).parents(".form-horizontal").attr('action', "{:url('notice_withdraw')}");
    })
    $('.tg').on('click',function () {
        $(this).parents(".form-horizontal").attr('action',"{:url('notice_pass')}");
    })
</script>

<script>
    //批量操作
    $('.plsh,.plbh').on('click', function(){
        var $tmpStatus = [];
        var msg = '';
        var type = 0;
        $(".checkbox:checked").each(function(){
            //判断状态
            if($tmpStatus.length < 1){
                $tmpStatus.push($(this).data('status'));
            }else if($.inArray($(this).data('status'),$tmpStatus) < 0){
                // layui.layer.msg('不同状态，不能批量操作');
                msg = '不同状态，不能批量操作';
                return false;
            }
        });
        if($tmpStatus.length == 0){
            layui.layer.msg('请选择');
            return false;
        }
        if(msg != ''){
            layui.layer.msg(msg);return false;
        }
        //判断人
        var $status = $tmpStatus[0];
        $(".checkbox:checked").each(function(){
            if($status === 0){
                if($(this).data('fuser') != {$user_id}) {
                    layui.layer.msg('审核状态不正确');
                    type = 1;
                    return false;
                }
            }else if($status == 1){
                if($(this).data('luser') != {$user_id}) {
                    layui.layer.msg('审核状态不正确');
                    type = 1;
                    return false;
                }
            }else{
                type = 1;
                layui.layer.msg('审核状态不正确');
                return false;
            }
        });
        if(type == 1){
            layui.layer.msg('审核状态不正确');
            return false;
        }
        ajax_submit_all(this);

    });

    //批量撤回
    $('.plch').on('click', function(){
        var $status = '';
        var msg = '';
        var type = 0;
        var $tmpStatus = [];
        $(".checkbox:checked").each(function(){
            //判断状态
            $tmpStatus.push($(this).data('status'));
            if($(this).data('status') != 1) {
                // layui.layer.msg('状态必须相同才可以撤回');
                msg = '状态不正确';
                return false;
            }
            $status = $(this).data('status');
        });
        if($tmpStatus.length == 0){
            layui.layer.msg('请选择');
            return false;
        }
        if(msg != ''){
            layui.layer.msg(msg);return false;
        }
        //判断人
        $(".checkbox:checked").each(function(){
            if($(this).data('fuser') != "{$user_id}"){  //终审人撤回待终审
                layui.layer.msg('审核状态不正确');
                type = 1;
                return false;
            }
        });
        if(type == 1){
            layui.layer.msg('审核状态不正确');
            return false;
        }
        ajax_submit_all(this);

    });

    // //批量驳回
    // $('.plbh').on('click', function(){
    //     var msg = '';
    //     $(".checkbox:checked").each(function(){
    //         //判断状态
    //         if($(this).data('status') > 1) {
    //             // layui.layer.msg('状态必须相同才可以驳回');
    //             msg = '状态必须相同才可以驳回';
    //             return false;
    //         }
    //     });
    //
    //     if(msg != '') layui.layer.msg(msg);return false;
    //
    //     //判断人
    //     $(".checkbox:checked").each(function(){
    //         if($status == 1 && $(this).data('luser') != "{$user_id}"){  //初审人撤回待终审
    //             layui.layer.msg('批量驳回，必须是同一人');
    //             return false;
    //         }else if($status == 0 && $(this).data('fuser') != "{$user_id}"){    //记录人撤回待初审
    //             layui.layer.msg('批量驳回，必须是同一人');
    //             return false;
    //         }
    //     });
    //
    // });
</script>
<!-- 拟稿提交按钮触发弹窗_ -->
<script>
    $(".audit_sub_submit,.bh_sub_submit,.ch_sub_submit").click(function () {
        var item = $(this);
        var className = item.attr("class");
        if(className.indexOf("ch_sub_submit") != -1){
            item.parents(".form-horizontal").find(".submits").click();
        }else {
            $('#myModal2').modal('show');
            $("#tips_submit").click(function () {
                var check_opinion = $("#check_opinion_textarea").val();
                console.log(check_opinion);
                if (className.indexOf("bh_sub_submit") != -1) {
                    if (check_opinion == '') {
                        layui.layer.msg('驳回意见必填！');
                        return false;
                    }
                }
                item.parents(".form-horizontal").find("input[name='check_opinion']").val(check_opinion);
                item.parents(".form-horizontal").find(".submits").click();
                $('#myModal2').modal('hide');
            });
        }
        return false;
    });
</script>
<!-- 拟稿提交按钮触发弹窗DOM结构_ -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
    <div class="modal-dialog" role="document">
        <div class="modal-content move">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel2">提示</h4>
            </div>
            <div class="modal_body" style="width: 100%;padding: 20px;">
                <label style="width: 100%;margin: 0;">
                    请填写您的意见：
                    <textarea name="check_opinion_textarea" id="check_opinion_textarea" cols="45" rows="5"
                              style="display: block;width: 100%;max-height: 100px; margin:0;padding: 10px;border-radius: 5px;"
                              placeholder="可以输入一千字"></textarea>
                </label>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="tips_submit">确认</button>
            </div>
        </div>
    </div>
</div>

{/block}